<?php
namespace Home\Controller;
use Think\Controller;
class PostController extends Controller {
    public function getType(){    
        $post_type = D('post_type');
        $type = $post_type->where(array())->select(); 
        $uid = session("uid");
        if($uid) {
            if($type) {
                $message['status'] = 1;
                $message['type'] = $type;           
            }else {
                $message['status'] = 2;
                $message['type'] = ""; 
            }
        } else {
            $message['status'] = 0;
            $message['type'] = ""; 
        }
        $this->ajaxReturn($message);
    }

    public function getPost() {  
        $typeId =  I('post.post_type', '');        
        $uid = session("uid");
        $user = M("user");
        $postType = M("post_type"); 
        $typeName = $postType->where(array("type_id"=>$typeId))->find(); 
        $data['post_createtime'] = date("Y-m-d H:i:s");
        $data['post_title'] = I('post.post_title', '');
        $data['post_content'] = I('post.post_content', '');
        $data['post_text'] = I('post.post_text', '');
        $data['post_image'] = I('post.post_image', '');
        $data['post_admin'] = session("userName");
        $data['post_uid'] = session("uid");
        $data['post_type'] = $typeName["type_name"];
        $post = M('post');
        $post->add($data);
        $message['status'] = 1;
        $this->ajaxReturn($message);
    }
}


